package cn.fintecher.pangolin.service.manage.web;

import cn.fintecher.pangolin.common.enums.BaseStatus;
import cn.fintecher.pangolin.common.web.BaseController;
import cn.fintecher.pangolin.service.manage.request.ModifyStatusRequest;
import cn.fintecher.pangolin.service.manage.response.UserDeviceResponse;
import cn.fintecher.pangolin.service.manage.service.UserDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Auther: xiaqun
 * @Description: 设备锁相关接口
 * @Date: 15:24 2019/8/15
 */

@RestController
@RequestMapping("/api/userDeviceController")
@Api(value = "设备锁相关接口", description = "设备锁相关接口")
public class UserDeviceController extends BaseController {
    @Autowired
    private UserDeviceService userDeviceService;

    /**
     * 设备锁查询
     */
    @ApiOperation(value = "设备锁查询", notes = "设备锁查询")
    @GetMapping("/findAllUserDevice")
    public ResponseEntity<List<UserDeviceResponse>> findAllUserDevice(@RequestParam @ApiParam(value = "用户ID", required = true) String userId) {
        log.info("REST request to find all user device,{}", userId);
        List<UserDeviceResponse> list = userDeviceService.findAllUserDevice(userId);
        return ResponseEntity.ok().body(list);
    }

    /**
     * 一键启/禁用设备锁
     */
    @ApiOperation(value = "一键启/禁用设备锁", notes = "一键启/禁用设备锁")
    @GetMapping("/batchDeviceManage")
    public ResponseEntity<Void> batchDeviceManage(@RequestParam @ApiParam(value = "设备状态", required = true) BaseStatus status) {
        log.info("REST request to batch device manage,{}", status);
        userDeviceService.batchDeviceManage(status);
        return ResponseEntity.ok().build();
    }

    /**
     * 启用/禁用设备
     */
    @ApiOperation(value = "启用/禁用设备", notes = "启用/禁用设备")
    @PutMapping("/modifyStatus")
    public ResponseEntity<Void> modifyStatus(@Valid @RequestBody ModifyStatusRequest request) {
        log.info("REST request to modify status,{}", request);
        userDeviceService.modifyStatus(request);
        return ResponseEntity.ok().build();
    }

    /**
     * 重置设备
     */
    @ApiOperation(value = "重置设备", notes = "重置设备")
    @DeleteMapping("/deleteUserDevice")
    public ResponseEntity<Void> deleteUserDevice(@RequestParam @ApiParam(value = "设备锁ID", required = true) String userDeviceId) {
        log.info("REST request to delete user device,{}", userDeviceId);
        userDeviceService.deleteUserDevice(userDeviceId);
        return ResponseEntity.ok().build();
    }
}